package com.gy.api.pc.movie.service.impl;

import cn.hutool.core.util.IdUtil;
import com.gy.api.base.IDEntity;
import com.gy.api.base.Type;
import com.gy.api.pc.examine.dao.ExamineDao;
import com.gy.api.pc.examine.dao.ExamineLogDao;
import com.gy.api.pc.examine.domain.vo.ExamineCompleteUserVO;
import com.gy.api.pc.examine.domain.vo.ExamineCompleteVO;
import com.gy.api.pc.filings.domain.vo.WcContentExamineListVO;
import com.gy.api.pc.movie.dao.FilmPermitInfoDao;
import com.gy.api.pc.movie.dao.WcContentExamineAncillaryDao;
import com.gy.api.pc.movie.dao.WcContentExamineDao;
import com.gy.api.pc.movie.domain.po.FilmPermitInfoPO;
import com.gy.api.pc.movie.domain.vo.*;
import com.gy.api.pc.movie.service.IFilmPermitInfoService;
import com.gy.api.pc.movie.service.IWcContentExamineService;
import com.gy.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
@Slf4j
public class FilmPermitInfoServiceImpl implements IFilmPermitInfoService {
    @Autowired
    FilmPermitInfoDao filmPermitInfoDao;

    @Override
    public List<FilmPermitInfoVO> getList(FilmPermitInfoSearchVO searchVO) {
        return filmPermitInfoDao.getList(searchVO);
    }

    @Override
    public void insertFilmPermitInfo(FilmPermitInfoAddVO filmPermitInfo) {
        FilmPermitInfoPO filmPermitInfoPO=new FilmPermitInfoPO();
        BeanUtils.copyProperties(filmPermitInfo, filmPermitInfoPO);
        filmPermitInfoPO.setId(IdUtil.getSnowflakeNextIdStr());
        filmPermitInfoPO.setAnnouncementDate(new Date());
        filmPermitInfoDao.insertSelective(filmPermitInfoPO);
    }

    @Override
    public void updateFilmPermitInfo(FilmPermitInfoUpdateVO updateVO) {
        FilmPermitInfoPO filmPermitInfoPO=filmPermitInfoDao.selectByPrimaryKey(updateVO.getId());
        if(filmPermitInfoPO==null){
            throw new BusinessException(Type.NOT_FOUND_ERROR.getCode(),  "信息不存在");
        }
        BeanUtils.copyProperties(updateVO, filmPermitInfoPO);
        filmPermitInfoDao.updateByPrimaryKeySelective(filmPermitInfoPO);
    }

    @Override
    public void deleteFilmPermitInfoByIds(List<String> ids) {
        for (String id:ids){
            FilmPermitInfoPO filmPermitInfoPO=filmPermitInfoDao.selectByPrimaryKey(id);
            if(filmPermitInfoPO==null){
                throw new BusinessException(Type.NOT_FOUND_ERROR.getCode(),  "信息不存在");
            }
            filmPermitInfoDao.deleteByPrimaryKey(id);
        }
    }

    @Override
    public FilmPermitInfoVO getOne(String id) {
        FilmPermitInfoPO filmPermitInfoPO=filmPermitInfoDao.selectByPrimaryKey(id);
        if(filmPermitInfoPO==null){
            throw new BusinessException(Type.NOT_FOUND_ERROR.getCode(),  "信息不存在");
        }
        FilmPermitInfoVO filmPermitInfoVO=new FilmPermitInfoVO();
        BeanUtils.copyProperties(filmPermitInfoPO, filmPermitInfoVO);
        return filmPermitInfoVO;
    }
}